package logic

import (
	"context"
	"errors"
	"work-safety/models/mysql"

	"work-safety/workrpc/internal/svc"
	"work-safety/workrpc/workrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
	return &LoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LoginLogic) Login(in *workrpc.LoginRequest) (*workrpc.LoginResponse, error) {
	// todo: add your logic here and delete this line
	data := mysql.User{

		Account:  in.Account,
		Password: in.Password,
	}
	if in.Password != data.Password {
		return nil, errors.New("密码错误")
	}
	mysql.DB.Debug().Find(&data)
	return &workrpc.LoginResponse{
		UserId: int64(data.ID),
	}, nil
}
